package cn.icanci.loopstack.bic.biz.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.icanci.loopstack.bic.biz.mapper.UnitViewMapper;
import cn.icanci.loopstack.bic.biz.service.UnitViewService;
import cn.icanci.loopstack.bic.common.model.graph.UnitViewVO;
import cn.icanci.loopstack.bic.dal.mongo.common.PageList;
import cn.icanci.loopstack.bic.dal.mongo.daointerface.UnitViewDAO;
import cn.icanci.loopstack.bic.dal.mongo.dateobject.UnitViewDO;

/**
 * @author icanci
 * @since 1.0 Created in 2023/09/16 11:11
 */
@Service
public class UnitViewServiceImpl implements UnitViewService {

    @Resource
    private UnitViewDAO    unitViewDAO;
    @Resource
    private UnitViewMapper unitViewMapper;

    @Override
    public List<UnitViewVO> queryAll() {
        return unitViewMapper.dos2vos(unitViewDAO.queryAll());
    }

    @Override
    public void save(UnitViewVO unitViewVO) {
        // TODO 日志记录
        if (doInsert(unitViewVO)) {
            UnitViewDO insert = unitViewMapper.vo2do(unitViewVO);
            unitViewDAO.insert(insert);
        } else {
            unitViewDAO.update(unitViewMapper.vo2do(unitViewVO));
        }
    }

    @Override
    public UnitViewVO queryById(String id) {
        return unitViewMapper.do2vo(unitViewDAO.queryOneById(id));
    }

    @Override
    public PageList<UnitViewVO> queryPage(UnitViewVO unitViewVO, int pageNum, int pageSize) {
        PageList<UnitViewDO> pageQuery = unitViewDAO.pageQuery(unitViewMapper.vo2do(unitViewVO), pageNum, pageSize);
        return new PageList<>(unitViewMapper.dos2vos(pageQuery.getData()), pageQuery.getPaginator());
    }

    @Override
    public UnitViewVO queryBySystemUuidAndUseCaseUuid(String systemUuid, String useCaseUuid) {
        return unitViewMapper.do2vo(unitViewDAO.queryBySystemUuidAndUseCaseUuid(systemUuid, useCaseUuid));
    }

    @Override
    public List<UnitViewVO> queryBySystemUuid(String systemUuid) {
        return unitViewMapper.dos2vos(unitViewDAO.queryBySystemUuid(systemUuid));
    }
}
